package com.jiangyg.mall.coupon.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.coupon.dto.SpuBoundsDTO;
import com.jiangyg.mall.coupon.service.SpuBoundsService;
import com.jiangyg.mall.coupon.vo.SpuBoundsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：商品spu积分设置控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-18 21:33:04
 */
@RestController
@RequestMapping("/coupon/bounds")
public class SpuBoundsController {

    /**
     * 商品spu积分设置接口
     */
    private final SpuBoundsService spuBoundsService;

    @Autowired
    public SpuBoundsController(SpuBoundsService spuBoundsService) {
        this.spuBoundsService = spuBoundsService;
    }

    /**
     * 功能描述：商品spu积分设置分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页商品spu积分设置
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<SpuBoundsVO>> select(HttpServletRequest request, @RequestBody Pagination<SpuBoundsVO> pagination) throws Exception {
        return Result.ok(spuBoundsService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改商品spu积分设置
     *
     * @param request 请求
     * @param dto     商品spu积分设置
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated SpuBoundsDTO dto) throws Exception {
        return Result.saveOrUpdate(spuBoundsService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取商品spu积分设置
     *
     * @param request 请求
     * @param spuBoundsId  商品spu积分设置ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<SpuBoundsVO> info(HttpServletRequest request, @RequestParam(name = "spuBoundsId") Long spuBoundsId) throws Exception {
        return Result.ok(spuBoundsService.selectById(spuBoundsId));
    }

    /**
     * 功能描述：删除商品spu积分设置
     *
     * @param request 请求
     * @param spuBoundsIds 批量删除的商品spu积分设置ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestBody List<Long> spuBoundsIds) {
        return Result.delete(spuBoundsService.delete(spuBoundsIds));
    }

}
